<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isErrorPage="true" %>
<html>
<head>
  <title>500 - 服务器内部错误</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body {
      font-family: 'Arial', sans-serif;
      background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .error-container {
      background: white;
      padding: 40px;
      border-radius: 10px;
      box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
      text-align: center;
      max-width: 600px;
      width: 90%;
    }

    .error-code {
      font-size: 80px;
      font-weight: bold;
      color: #dc3545;
      margin-bottom: 20px;
    }

    .error-title {
      font-size: 24px;
      color: #333;
      margin-bottom: 15px;
    }

    .error-message {
      color: #666;
      margin-bottom: 20px;
      line-height: 1.6;
    }

    .error-details {
      background: #f8f9fa;
      border: 1px solid #e9ecef;
      border-radius: 5px;
      padding: 15px;
      margin: 20px 0;
      text-align: left;
      font-family: 'Courier New', monospace;
      font-size: 14px;
      max-height: 200px;
      overflow-y: auto;
    }

    .action-buttons {
      display: flex;
      gap: 15px;
      justify-content: center;
      flex-wrap: wrap;
      margin-top: 20px;
    }

    .btn {
      display: inline-block;
      padding: 10px 20px;
      background: #007bff;
      color: white;
      text-decoration: none;
      border-radius: 5px;
      transition: background 0.3s;
      border: none;
      cursor: pointer;
    }

    .btn:hover {
      background: #0056b3;
    }

    .btn-home {
      background: #28a745;
    }

    .btn-home:hover {
      background: #218838;
    }

    .btn-back {
      background: #6c757d;
    }

    .btn-back:hover {
      background: #545b62;
    }

    .technical-info {
      margin-top: 20px;
      padding-top: 20px;
      border-top: 1px solid #eee;
      font-size: 12px;
      color: #999;
    }
  </style>
</head>
<body>
<div class="error-container">
  <div class="error-code">500</div>
  <h1 class="error-title">服务器内部错误</h1>
  <p class="error-message">
    抱歉，服务器遇到了一个意外错误。<br>
    我们的技术团队已经收到通知，正在处理这个问题。
  </p>

  <%-- 显示错误详情（仅在开发环境） --%>
  <%
    if (exception != null) {
  %>
  <div class="error-details">
    <strong>错误类型:</strong> <%= exception.getClass().getName() %><br>
    <strong>错误信息:</strong> <%= exception.getMessage() %><br>
    <br>
    <strong>堆栈跟踪:</strong><br>
    <%
      java.io.StringWriter sw = new java.io.StringWriter();
      java.io.PrintWriter pw = new java.io.PrintWriter(sw);
      exception.printStackTrace(pw);
      out.print(sw.toString().replace("\n", "<br>").replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;"));
    %>
  </div>
  <%
    }
  %>

  <div class="action-buttons">
    <a href="${pageContext.request.contextPath}/dashboard" class="btn btn-home">返回首页</a>
    <a href="javascript:history.back()" class="btn btn-back">返回上页</a>
    <a href="${pageContext.request.contextPath}/login" class="btn">重新登录</a>
    <button onclick="location.reload()" class="btn">刷新页面</button>
  </div>

  <div class="technical-info">
    如果问题持续存在，请联系系统管理员。<br>
    错误时间: <%= new java.util.Date() %>
  </div>
</div>
</body>
</html>